"use strict"; !
function(o) {
    o.factory("userDialog", ["dialog", "api",
    function(o, e) {
        var n = {};
        return n.editInfo = function(n) {
            var r = n.name,
            t = n.id,
            i = n.email,
            m = n.phone;
            return o.common({
                title: "修改资料",
                buttons: o.buttons.BUTTON_OK_CANCEL,
                template: '\n          <form name="modifyInfo"><form-container left-column-width="80">\n            <form-config-group ng-show="data.id !== undefined">\n              <form-config-item config-title="用户名">\n                <span ng-bind="data.name"></span>\n              </form-config-item>\n              <form-config-item config-title="邮箱">\n                <input placeholder="请输入邮箱地址" type="email" name="email" required ng-model="data.email" />\n                <form-error-message form="modifyInfo" target="email" type="required">请输入邮箱地址</form-error-message>\n                <form-error-message form="modifyInfo" target="email" type="email">邮箱地址格式不正确</form-error-message>\n              </form-config-item>\n              <form-config-item config-title="电话">\n                <input placeholder="请输入电话号码" type="tel" name="phone" ng-model="data.phone" />\n                <form-error-message form="modifyInfo" target="phone" type="required">请输入电话号码</form-error-message>\n                <form-error-message form="modifyInfo" target="phone" type="pattern">电话号码格式不正确</form-error-message>\n              </form-config-item>\n            </form-config-group>\n            <button ng-show="false"></button>\n          </form-container></form>\n        ',
                size: 600,
                controller: ["$scope",
                function(n) {
                    n.data = {
                        id: t,
                        name: r,
                        email: i,
                        phone: m
                    },
                    n.onbeforeclose = function(e) {
                        if (e === o.button.BUTTON_OK) return n.formSubmit(),
                        !1
                    },
                    n.formSubmit = function() {
                        n.modifyInfo.$setSubmitted(),
                        n.modifyInfo.$invalid || e.user.modify(n.data).then(function() {
                            o.tip("修改资料成功", "修改资料成功。").then(function() {
                                return n.resolve(o.button.BUTTON_OK)
                            })
                        },
                        function(e) {
                            o.error("修改资料失败", "修改密码失败，请重试。")
                        })
                    }
                }]
            })
        },
        n.editPassword = function(n) {
            return o.common({
                title: "修改密码",
                buttons: o.buttons.BUTTON_OK_CANCEL,
                template: '\n          <form name="modifyPassword"><form-container left-column-width="80">\n            <form-config-group>\n              <form-config-item config-title="用户名" ng-if="isAdmin === true">\n                <span ng-bind="username"></span>\n              </form-config-item>\n              <form-config-item config-title="原密码" ng-if="isAdmin === false">\n                <input placeholder="请输入原密码" type="password" name="old" ng-model="data.oldPassword" required />\n                <form-error-message form="modifyPassword" target="old">请输入原密码</form-error-message>\n              </form-config-item>\n              <form-config-item config-title="新密码">\n                <input placeholder="密码长度应为 8 ～ 20 位" type="password" name="password" required pattern="^.{8,20}$" ng-model="data.newPassword" />\n                <form-error-message form="modifyPassword" target="password" type="required">请输入新密码</form-error-message>\n                <form-error-message form="modifyPassword" target="password" type="pattern">密码长度应为 8 ～ 20 位</form-error-message>\n              </form-config-item>\n              <form-config-item config-title="确认密码">\n                <input placeholder="请再次输入新密码" type="password" name="verify" ng-model="data.verifyPassword" />\n                <form-error-message form="modifyPassword" condition="data.newPassword && data.newPassword !== data.verifyPassword">两次输入的密码不一致</form-error-message>\n              </form-config-item>\n            </form-config-group>\n            <button ng-show="false"></button>\n          </form-container></form>\n        ',
                size: 600,
                controller: ["$scope",
                function(r) {
                    r.username = n,
                    r.isAdmin = null,
                    e.user.whoami().then(function(o) {
                        var e = o.isAdmin,
                        n = o.name;
                        r.isAdmin = e,
                        r.currentUser = n
                    }),
                    r.data = {
                        oldPassword: "",
                        newPassword: "",
                        verifyPassword: ""
                    },
                    r.onbeforeclose = function(e) {
                        if (e === o.button.BUTTON_OK) return r.modifyPassword.$setSubmitted(),
                        r.modifyPassword.$invalid || r.formSubmit(),
                        !1
                    },
                    r.formSubmit = function() {
                        e.user.passwd(Object.assign({
                            name: n,
                            newPassword: r.data.newPassword
                        },
                        r.isAdmin ? {}: {
                            oldPassword: r.data.oldPassword
                        })).then(function() {
                            if (r.isAdmin) {
                                var e = void 0;
                                e = n === r.currentUser ? o.tip("修改密码成功", "您的密码已修改，下次登录时请使用新密码登录。") : o.tip("修改密码成功", "用户 " + n + " 的密码已修改，下次登录时请使用新密码登录。"),
                                e.then(function() {
                                    r.resolve(o.button.BUTTON_OK)
                                })
                            } else o.alert("修改密码成功", "修改密码成功，请重新登录。").then(function() {
                                location.href = "/login/login.html?redirect=" + encodeURIComponent(location.href)
                            })
                        },
                        function(e) {
                            o.error("修改密码失败", "修改密码失败，" + (e ? e + "，": "") + "请重试。")
                        })
                    }
                }]
            })
        },
        n
    }])
} (angular.module("commonDialogs", ["pageLayout", "backendApi"]));